package com.hailong.zyt.intercepter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Slf4j
public class AdminIdentityInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        String identity = (String) session.getAttribute("userType");
        if("admin".equals(identity)) {
            return true;
        }
        else{
            log.info("管理员身份拦截器：{}", request.getRequestURI());
            return false;
        }
    }

}
